﻿using System;
using UnityEngine;

/******************************************************************
 * GOAL STATS
 * 
 * For initialize : 
 *                  E_PropKey.E_WEAPON_IN_HANDS     false
 *                  E_PropKey.E_ALERTED             true    
 * For planing : 
 *                  E_PropKey.E_WEAPON_IN_HANDS     true
 * Set : 
 *                  
 * Finished:
 *                  E_WEAPON_IN_HANDS                true
 * 
 * ***************************************************************/

/// <summary>
/// 作用是装备武器
/// </summary>
class GOAPGoalAlert : GOAPGoal
{
    public GOAPGoalAlert(Agent owner) : base(E_GOAPGoals.E_ALERT, owner) { }

	public override void InitGoal()
	{

	}

    public override float GetMaxRelevancy()
    {
        return Owner.BlackBoard.GOAP_AlertRelevancy;
    }

	public override void CalculateGoalRelevancy()
	{
        GoalRelevancy = 0;

//        if (Owner.BlackBoard.DesiredTarget == null)
//            return;

        WorldStateProp prop = Owner.WorldState.GetWSProperty(E_PropKey.E_WEAPON_IN_HANDS);
        WorldStateProp prop2 = Owner.WorldState.GetWSProperty(E_PropKey.E_ALERTED);
        if (prop != null  && prop2 != null && prop.GetBool() == false && prop2.GetBool() == true)
            GoalRelevancy = Owner.BlackBoard.GOAP_AlertRelevancy;
	}

	public override void SetDisableTime() { NextEvaluationTime = Owner.BlackBoard.GOAP_AlertDelay + Time.timeSinceLevelLoad;}

    /// <summary>
    /// 我要的是一个满足这个条件的世界，请帮我找一条路径（动作序列）去实现它。
    /// </summary>
    /// <param name="worldState"></param>
	public override void SetWSSatisfactionForPlanning(WorldState worldState)
	{
        worldState.SetWSProperty(E_PropKey.E_WEAPON_IN_HANDS, true);
	}

    /// <summary>
    /// 判断当前世界状态是否已经满足了该目标在“规划阶段”所定义的满足条件。
    /// 这是 GOAP 在执行行为规划（Plan）时，用来检查目标是否“已经达成”的逻辑判断方法。
    /// 备注：该方法与IsSatisfied类似，不过执行时机不一样
    /// IsWSSatisfiedForPlanning：计划生成阶段
    /// IsSatisfied：实际执行阶段
    /// 简单说：IsWSSatisfiedForPlanning 是**“理论上达成目标了吗？”**
    /// 而 IsSatisfied 是**“现在真的完成目标了吗？”**
    /// </summary>
    /// <param name="worldState"></param>
    /// <returns></returns>
	public override bool IsWSSatisfiedForPlanning(WorldState worldState)
	{
        WorldStateProp prop = worldState.GetWSProperty(E_PropKey.E_WEAPON_IN_HANDS);
		if (prop.GetBool() == true)
			return true;

		return false;
	}

    /// <summary>
    /// 在运行时判断目标是否完成
    /// 备注：该方法与IsWSSatisfiedForPlanning类似，不过执行时机不一样
    /// IsWSSatisfiedForPlanning：计划生成阶段
    /// IsSatisfied：实际执行阶段
    /// 简单说：IsWSSatisfiedForPlanning 是**“理论上达成目标了吗？”**
    /// 而 IsSatisfied 是**“现在真的完成目标了吗？”**
    /// </summary>
    /// <returns></returns>
    public override bool IsSatisfied()
    {
        WorldStateProp prop = Owner.WorldState.GetWSProperty(E_PropKey.E_WEAPON_IN_HANDS);
        if (prop.GetBool() == true)
            return true;

        return false;
    }
}

